//
//  InformationViewController.m
//  HondaPro_2
//
//  Created by ht on 13-6-24.
//  Copyright (c) 2013年 glendale. All rights reserved.
//

#import "InformationViewController.h"
#import <QuartzCore/QuartzCore.h>
#import "VehicleDataEditViewController.h"
#import "UIViewController+MJPopupViewController.h"
#import "CustomerDetailsViewController.h"
#import "webConfig.h"
#import "webService.h"
#import "SVProgressHUD.h"
#import "MJRefresh.h"
#import "MyAFNetWorkManager.h"

#define NUMBERS @"0123456789\n"
@interface InformationViewController ()
{
    BOOL _tableViewchoose;
    int _isTheButtonTag;
    BOOL _state;
    
//    车主 from-to
    NSInteger toZ;
    NSInteger fromZ;
    
//   车辆from-to
    NSInteger toL;
    NSInteger fromL;
    
}

@end

@implementation InformationViewController

@synthesize vehiclefield1 = _vehiclefield1;
@synthesize vehiclefield2 = _vehiclefield2;
@synthesize vehiclefield3 = _vehiclefield3;
@synthesize vehiclefield4 = _vehiclefield4;

@synthesize entrylabel1 = _entrylabel1;
@synthesize entrylabel2 = _entrylabel2;
@synthesize entrylabel3 = _entrylabel3;
@synthesize entrybutton1 = _entrybutton1;
@synthesize entrybutton2 = _entrybutton2;
@synthesize entrybutton3 = _entrybutton3;

@synthesize detailTableView = _detailTableView;
@synthesize detailTableView2 = _detailTableView2;

@synthesize datePicker = _datePicker;
@synthesize dataString = _dataString;
@synthesize datadictionary = _datadictionary;

@synthesize tableViewLabel = _tableViewLabel;
@synthesize tabelViewaLableArray = _tabelViewaLableArray;

@synthesize secondfield1 = _secondfield1;
@synthesize secondfield2 = _secondfield2;
@synthesize secondfield3 = _secondfield3;

@synthesize choosebutton1 = _choosebutton1;
@synthesize choosebutton2 = _choosebutton2;

@synthesize secondlabel1 = _secondlabel1;
@synthesize secondlabel2 = _secondlabel2;
@synthesize secondlabel3 = _secondlabel3;

@synthesize secondbutton1 = _secondbutton1;
@synthesize secondbutton2 = _secondbutton2;
@synthesize secondbutton3 = _secondbutton3;

@synthesize tableViewDataArrS = _tableViewDataArrS;
@synthesize tableViewDataArrX = _tableViewDataArrX;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self)
    {

    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
//    初始化车主车辆 to与from
    fromL = 1;
    fromZ = 1;
    
    toL = 10;
    toZ =10;
    
    //车型
    self.carTypeArray = [[NSMutableArray alloc]init];
    //车系
    self.carClassArray = [[NSMutableArray alloc]init];
    
    [self loadinputPicture];

    [self loadfixedPicture];
    [self loadSecondPartPicture];
    [self loadtitlelabelPicture];
    [self loadNewTitleLabelPicture];
    
        self.detailTableView = [[UITableView alloc]initWithFrame:CGRectMake(60, 255, 918, 135) style:UITableViewStylePlain];
    [self.detailTableView setDataSource:self];
    [self.detailTableView setDelegate:self];
    [self.view addSubview:self.detailTableView];
    
    self.detailTableView2 = [[UITableView alloc]initWithFrame:CGRectMake(60, 565, 918, 135) style:UITableViewStylePlain];
    [self.detailTableView2 setDataSource:self];
    [self.detailTableView2 setDelegate:self];
    [self.view addSubview:self.detailTableView2];
    
    //添加一个UITapGesture用于隐藏键盘
    UITapGestureRecognizer *tapGr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped:)];
    tapGr.cancelsTouchesInView = NO;
    [self.view addGestureRecognizer:tapGr];
    
    self.tableViewDataArrS = [[NSMutableArray alloc]init];
    self.tableViewDataArrX = [[NSMutableArray alloc]init];
    
    //[self VehicleQuery:nil];
    //[self VehicleQuery2:nil];
    
    __unsafe_unretained UITableView *table1 = self.detailTableView;
    table1.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
//        [self.tableViewDataArrS removeAllObjects];
         toZ = 10;
        [self VehicleQuery:nil];
       
        [table1.mj_header endRefreshing];
    }];
    
    
    table1.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
        toZ = toZ +10;
        [self VehicleQuery:nil];
        [table1.mj_footer endRefreshing];
    }];
    
    
    __unsafe_unretained UITableView *table2 = self.detailTableView2;
    table2.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
//        [self.tableViewDataArrX removeAllObjects];
        toL = 10;
        [self VehicleQuery2:nil];
        [table2.mj_header endRefreshing];
    }];
    
    
    table2.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
        toL = toL + 10;
        [self VehicleQuery2:nil];
        [table2.mj_footer endRefreshing];
    }];
    
    _state = YES;
    
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    
    //[self addNotification];
    
//    MainMenuDataModel *modelIns = [MainMenuDataModel sharedMainMenuDataModel];
//    
//    self.secondfield1.text = @"";
//    self.secondfield2.text = @"";
//    self.secondfield3.text = modelIns.currentVinSel;
//    self.vehiclefield1.text = modelIns.strCurrentCustomerName;
    /*
     //车架号
     modelIns.currentVinSel;
     //车牌号
     modelIns.strCurrentPlateNumber;
     //车主姓名
     modelIns.strCurrentCustomerName;
     */
//    webService *webcon = [[webService alloc]init];
//    webcon.methodName = GETMANUFACTURELIST;
//    [webcon commonGetSharedRequest:GETMANUFACTURELIST wsparas:nil];
//    //车辆颜色
//    webService *web=[[webService alloc] init];
//    web.methodName = GETCARCOLORLIST;
//    [web commonGetSharedRequest:GETCARCOLORLIST wsparas:nil];

    if (self.customerParamOut) {
        self.vehiclefield1.text = self.customerParamOut[@"CUSTOMER_NAME"];//客户名称
        [self VehicleQuery:nil];
    }
    if (self.carParamOut) {
        self.secondfield1.text = self.carParamOut[@"PLATE_NUMBER"];//车牌号
        self.secondfield3.text = self.carParamOut[@"vin"];//车架号
        [self VehicleQuery2:nil];
    }
    
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
//    清空两个表的数据
    [self.tableViewDataArrS removeAllObjects];
    [self.tableViewDataArrX removeAllObjects];
    
    MainMenuDataModel *modelIns = [MainMenuDataModel sharedMainMenuDataModel];
    
    self.secondfield1.text = modelIns.strCurrentPlateNumber = @"";
    self.secondfield2.text = modelIns.strCurrentCustomerName = @"";
    self.secondfield3.text = modelIns.currentVinSel = @"";
//    self.vehiclefield1.text = modelIns.strCurrentCustomerName = @"";
    //[self removeNotification];
}

-(void)viewTapped:(UITapGestureRecognizer*)tapGr                 //判断textField隐藏键盘
{
    if([self.secondfield1 resignFirstResponder])
    {
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.4];
        [self.view setFrame:CGRectMake(0, 0, 1024, 768)];
        [UIView commitAnimations];
    }
    else if([self.secondfield2 resignFirstResponder])
    {
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.4];
        [self.view setFrame:CGRectMake(0, 0, 1024, 768)];
        [UIView commitAnimations];
    }
    else if([self.secondfield3 resignFirstResponder])
    {
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.4];
        [self.view setFrame:CGRectMake(0, 0, 1024, 768)];
        [UIView commitAnimations];
    }
    [self.vehiclefield1 resignFirstResponder];
    [self.vehiclefield2 resignFirstResponder];
    [self.vehiclefield3 resignFirstResponder];
    [self.vehiclefield4 resignFirstResponder];
}
-(void)textFieldDidBeginEditing:(UITextField *)textField     //弹出键盘的时候上提
{
    if (self.secondfield1==textField) {
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.4];
        [self.view setFrame:CGRectMake(0, 0-150, 1024, 768)];
        [UIView commitAnimations];

    }
    else if(self.secondfield2==textField)
    {[UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.4];
        [self.view setFrame:CGRectMake(0, 0-150, 1024, 768)];
        [UIView commitAnimations];}
    else if(self.secondfield3==textField)
    {[UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.4];
        [self.view setFrame:CGRectMake(0, 0-150, 1024, 768)];
        [UIView commitAnimations];
    }
   }
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    
    return 1;

}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if(tableView == self.detailTableView)
    {
       
        return [self.tableViewDataArrS count];
    }
    else if(tableView == self.detailTableView2)
    {
    
        return [self.tableViewDataArrX count];
    }
    return 0;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(tableView == self.detailTableView2)
    {
//        车辆
        self.vehicledataeditViewController= [[VehicleDataEditViewController alloc]init];
        self.vehicledataeditViewController.cjhStr = [[self.tableViewDataArrX objectAtIndex:indexPath.row]objectForKey:@"VIN"];
        self.vehicledataeditViewController.cphStr = [[self.tableViewDataArrX objectAtIndex:indexPath.row]objectForKey:@"LICENSE"];
        
//车型
        NSArray *modelArr=[self readershuDICimform][@"MODEL"];
        NSString * modelStr;
        for (NSDictionary * dic in modelArr) {
            if ([dic[@"MODEL_CODE"] isEqualToString:[[self.tableViewDataArrX objectAtIndex:indexPath.row]objectForKey:@"MODEL"]]) {
                modelStr = dic[@"MODEL_NAME"];
            }
        }
        NSLog(@"---%@--",modelStr);
        self.vehicledataeditViewController.xhStr = modelStr;
        
//  车系
        NSArray *seriesArr=[self readershuDICimform][@"SERIES"];
        NSString * seriesStr;
        for (NSDictionary * dic in seriesArr) {
            if ([dic[@"SERIES_CODE"] isEqualToString:[[self.tableViewDataArrX objectAtIndex:indexPath.row]objectForKey:@"SERIES"]]) {
                seriesStr = dic[@"SERIES_NAME"];
            }
        }
        self.vehicledataeditViewController.cxStr = seriesStr;
        
        self.vehicledataeditViewController.fdjhStr =[[self.tableViewDataArrX objectAtIndex:indexPath.row]objectForKey:@"ENGINE_NUMBER"];
        self.vehicledataeditViewController.bsxhStr =[[self.tableViewDataArrX objectAtIndex:indexPath.row]objectForKey:@"GEAR_BOX_NUMBE"];
        
        self.vehicledataeditViewController.nkStr =[[self.tableViewDataArrX objectAtIndex:indexPath.row]objectForKey:@"YEAR"];
        self.vehicledataeditViewController.pqlStr =[[self.tableViewDataArrX objectAtIndex:indexPath.row]objectForKey:@"EMISSION"];
         self.vehicledataeditViewController.bzStr =[[self.tableViewDataArrX objectAtIndex:indexPath.row]objectForKey:@"REMARK"];
        
        
    
        
        NSArray *innerColorArr=[self readershuDICimform][@"INNER_COLOR"];
        NSString * innerColorStr;
        for(NSDictionary *dic in innerColorArr)
        {
            if ([dic[@"COLOR_CODE"] isEqualToString:[[self.tableViewDataArrX objectAtIndex:indexPath.row]objectForKey:@"INSIDE_COLOR"]]) {
                innerColorStr = dic[@"COLOR_NAME"];
            }
        }
        
        self.vehicledataeditViewController.nzysStr =innerColorStr;
        
        NSArray *outerColorArr=[self readershuDICimform][@"OUTER_COLOR"];
        NSString * outColorStr;
        for(NSDictionary *dic in outerColorArr)
        {
            if ([dic[@"COLOR_CODE"] isEqualToString:[[self.tableViewDataArrX objectAtIndex:indexPath.row]objectForKey:@"COLOR"]]) {
                outColorStr = dic[@"COLOR_NAME"];
            }
        }
        
        self.vehicledataeditViewController.ClysStr =outColorStr;
        
        self.vehicledataeditViewController.yshStr =[[self.tableViewDataArrX objectAtIndex:indexPath.row]objectForKey:@"KEY_NUMBER"];
        
        NSArray *carUseArr=[self readershuDICimform][@"VEHICLE_PURPOSE"];
        NSString * carUseStr;
        
        for(NSDictionary *dic in carUseArr)
        {
            if ([dic[@"CODE"] isEqualToString:[[[self.tableViewDataArrX objectAtIndex:indexPath.row]objectForKey:@"CAR_USE"] stringValue]]) {
                  carUseStr = dic[@"NAME"];
            }
          
        }
        
        //车辆用途
        self.vehicledataeditViewController.clytStr =carUseStr;
        NSArray *insuranceArr=[self readershuDICimform][@"TM_INSURANCE"];
        NSString * insuranceStr;
        
        for(NSDictionary *dic in insuranceArr)
        {
            if ([dic[@"CODE"] isEqualToString:[[self.tableViewDataArrX objectAtIndex:indexPath.row]objectForKey:@"INSURANCE_COMPANY"]]) {
                insuranceStr = dic[@"NAME"];
            }
            
        }
        //保险公司
        self.vehicledataeditViewController.bxgsStr =insuranceStr;
        
         self.vehicledataeditViewController.bxgmrqStr =[[[[self.tableViewDataArrX objectAtIndex:indexPath.row]objectForKey:@"INSURANCE_BUY_DATE"] componentsSeparatedByString:@" "]firstObject];
        
        self.vehicledataeditViewController.bxdqrqStr =[[[[self.tableViewDataArrX objectAtIndex:indexPath.row]objectForKey:@"INSURANCE_EXPIRES_DATE"] componentsSeparatedByString:@" "]firstObject];
        
         self.vehicledataeditViewController.gmrqStr =[[[[self.tableViewDataArrX objectAtIndex:indexPath.row]objectForKey:@"BUY_DATE"] componentsSeparatedByString:@" "]firstObject];
        
        self.vehicledataeditViewController.sprqStr =[[[[self.tableViewDataArrX objectAtIndex:indexPath.row]objectForKey:@"PLATE_DATE"] componentsSeparatedByString:@" "]firstObject];
        
        self.vehicledataeditViewController.dyclcrqStr =[[[[self.tableViewDataArrX objectAtIndex:indexPath.row]objectForKey:@"FIRST_COMING_DATE"] componentsSeparatedByString:@" "]firstObject];
        
         self.vehicledataeditViewController.zhyclclcStr =[[[self.tableViewDataArrX objectAtIndex:indexPath.row]objectForKey:@"LAST_COMING_MILEAGE"] stringValue];
        
        self.vehicledataeditViewController.khbhStr = [[self.tableViewDataArrX objectAtIndex:indexPath.row]objectForKey:@"OWNER_NO"];
        self.vehicledataeditViewController.khmcStr =[[self.tableViewDataArrX objectAtIndex:indexPath.row]objectForKey:@"OWNER_NAME"];
        
//        客户性质
        int nature = [[[self.tableViewDataArrX objectAtIndex:indexPath.row] objectForKey:@"OWNER_PROPERTY"] intValue];
     
        if (nature == 11901001) {
            self.vehicledataeditViewController.khxzStr = @"公司";
        }else{
            self.vehicledataeditViewController.khxzStr = @"个人";
        }
        
        self.vehicledataeditViewController.sjStr =[[self.tableViewDataArrX objectAtIndex:indexPath.row]objectForKey:@"MOBILE"];
        
        self.vehicledataeditViewController.lxdhStr =[[self.tableViewDataArrX objectAtIndex:indexPath.row]objectForKey:@"PHONE"];
        
        self.vehicledataeditViewController.lxrStr =[[self.tableViewDataArrX objectAtIndex:indexPath.row]objectForKey:@"CONTACTOR_NAME"];
        self.vehicledataeditViewController.lxdzStr = [[self.tableViewDataArrX objectAtIndex:indexPath.row]objectForKey:@"ADDRESS"];
        
        [self.navigationController pushViewController:self.vehicledataeditViewController animated:YES];

    }
    else if (tableView == self.detailTableView){
//        车主
//      self.customerDetailsViewController = [[CustomerDetailsViewController alloc]initWithNibName:@"CustomerDetailsViewController" bundle:nil];
        self.customerDetailsViewController = [[CustomerDetailsViewController alloc]init];
//        NSLog(@"---%@",[[self.tableViewDataArrS objectAtIndex:indexPath.row] objectForKey:@"CUSTOMER_ID"]);
        //客户编号
      self.customerDetailsViewController.khbhStr =[[self.tableViewDataArrS objectAtIndex:indexPath.row] objectForKey:@"CUSTOMER_ID"];
//        客户名称
        self.customerDetailsViewController.khmcStr = [[self.tableViewDataArrS objectAtIndex:indexPath.row] objectForKey:@"CUSTOMER_NAME"];
        
//        手机号
        self.customerDetailsViewController.sjhStr = [[self.tableViewDataArrS objectAtIndex:indexPath.row] objectForKey:@"MOBILE"];
        
//        客户性质
        int nature = [[[self.tableViewDataArrS objectAtIndex:indexPath.row] objectForKey:@"NATURE_NAME"] intValue];
        NSString * natureStr;
        if (nature == 11901001) {
            natureStr = @"公司";
        }else{
        natureStr = @"个人";
        }
        
        self.customerDetailsViewController.khxzStr =natureStr;
//        联系人
        self.customerDetailsViewController.lxrStr =[[self.tableViewDataArrS objectAtIndex:indexPath.row] objectForKey:@"CONTACT_MAN"];
        
//        联系电话
           self.customerDetailsViewController.lxdhStr =[[self.tableViewDataArrS objectAtIndex:indexPath.row] objectForKey:@"TEL"];
        
//        所在地区
     
        //省
        int province = [[[self.tableViewDataArrS objectAtIndex:indexPath.row] objectForKey:@"PROVINCE"] intValue];
        NSString * provinceStr;
         NSArray *provinceArr=[self readershuDICimform][@"PROVINCE"];
        for (NSDictionary * dic in provinceArr) {
            if ([dic[@"CODE"] intValue] == province) {
                provinceStr = dic[@"NAME"];
            }
        }
       
//        市
        int city = [[[self.tableViewDataArrS objectAtIndex:indexPath.row] objectForKey:@"CITY"] intValue];
        NSString * cityStr;
        NSArray *cityArr=[self readershuDICimform][@"CITY"];
        for (NSDictionary * dic in cityArr) {
            if ([dic[@"CODE"] intValue] == city) {
                cityStr = dic[@"NAME"];
            }
        }
        
//       地区
        int area = [[[self.tableViewDataArrS objectAtIndex:indexPath.row] objectForKey:@"DISTRICT"] intValue];
        NSString * areaStr;
        NSArray *areaArr=[self readershuDICimform][@"AREA"];
        for (NSDictionary * dic in areaArr) {
            if ([dic[@"CODE"] intValue] == area) {
                areaStr = dic[@"NAME"];
            }
        }
        
        NSString * suozaidiqu =[NSString stringWithFormat:@"%@ %@ %@",provinceStr,cityStr,areaStr];
        self.customerDetailsViewController.szdqStr =suozaidiqu;
        
//        地址
         self.customerDetailsViewController.lxdzStr =[[self.tableViewDataArrS objectAtIndex:indexPath.row] objectForKey:@"ADDRESS"];
//        性别
        int sex =[[[self.tableViewDataArrS objectAtIndex:indexPath.row] objectForKey:@"GENDER"]intValue];
        NSString * sexStr;
        if (sex == 10061002) {
            sexStr = @"女";
        }else{
        sexStr = @"男";
        }
        self.customerDetailsViewController.xbStr =sexStr;
//        10061002 nv
//        邮编
        self.customerDetailsViewController.ybStr = [[self.tableViewDataArrS objectAtIndex:indexPath.row] objectForKey:@"ZIP_CODE"];
//        出生日期
        self.customerDetailsViewController.csrqStr =[[[[self.tableViewDataArrS objectAtIndex:indexPath.row] objectForKey:@"BIRTHDAY"] componentsSeparatedByString:@" "] firstObject];
      
        //证件类型
        
      
        int cttype = [[[self.tableViewDataArrS objectAtIndex:indexPath.row] objectForKey:@"CERTIFICATE_TYPE"] intValue];
        NSString * cttypeStr;
          NSArray *CTTypeArr=[self readershuDICimform][@"CT_CODE"];
        for (NSDictionary * dic in CTTypeArr) {
            if ([dic[@"CODE"]intValue] == cttype) {
                cttypeStr = dic[@"NAME"];
            }
        }
//        [[[self.tableViewDataArrS objectAtIndex:indexPath.row] objectForKey:@"CERTIFICATE_TYPE"] stringValue];
        self.customerDetailsViewController.zjlxStr =cttypeStr;
        
//        证件号码
        self.customerDetailsViewController.zjhmStr =[[self.tableViewDataArrS objectAtIndex:indexPath.row] objectForKey:@"CERTIFICATE"];
        //兴趣爱好
        int hobbies = [[[self.tableViewDataArrS objectAtIndex:indexPath.row] objectForKey:@"HOBBIES"] intValue];
        NSString * hobbiesStr;
        NSArray *hobbiesArr=[self readershuDICimform][@"TM_HOBBY"];
        for (NSDictionary * dic in hobbiesArr) {
            if ([dic[@"CODE"] intValue] == hobbies) {
                hobbiesStr = dic[@"NAME"];
            }
        }
//        [[self.tableViewDataArrS objectAtIndex:indexPath.row] objectForKey:@"HOBBIES"]
        self.customerDetailsViewController.xqahStr =hobbiesStr;
        
        //婚姻状态
         int marital = [[[self.tableViewDataArrS objectAtIndex:indexPath.row] objectForKey:@"MARITAL"] intValue];
         NSString * maritalStr;
        if (marital == 11191002) {
            maritalStr = @"已婚";
        }else{
            maritalStr = @"未婚";
        }
      
//        [[[self.tableViewDataArrS objectAtIndex:indexPath.row] objectForKey:@"MARITAL"] stringValue]
        self.customerDetailsViewController.hyztStr =maritalStr;
//        备注
        self.customerDetailsViewController.bzStr = [[self.tableViewDataArrS objectAtIndex:indexPath.row] objectForKey:@"REMARK"];
        
        
    [self.navigationController pushViewController:self.customerDetailsViewController animated:YES];
    }
//        return;
//    [SVProgressHUD showWithStatus:@"请等待...."];
//    NSString *actionID;
//    NSDictionary *dic;
//    if(tableView == self.detailTableView2)
//    {
////        webService *webcon = [[webService alloc]init];
////        webcon.methodName = GETREPAIRCARDETAIL;
////        NSMutableArray *arry = [NSMutableArray arrayWithObjects:@"vin",[[self.tableViewDataArrX objectAtIndex:indexPath.row]objectForKey:@"vin"], nil];
////        [webcon commonGetSharedRequest:GETREPAIRCARDETAIL wsparas:arry];
//        
////        dic = @{@"VIN":[[self.tableViewDataArrX objectAtIndex:indexPath.row]objectForKey:@"VIN"]};
//        
//    }
//    
//    else if(tableView == self.detailTableView)
//    {
////        webService *webcon = [[webService alloc]init];
////        webcon.methodName = GETREPAIRCUSTOMERDETAIL;
////        NSMutableArray *arry = [NSMutableArray arrayWithObjects:@"customerId",[[self.tableViewDataArrS objectAtIndex:indexPath.row] objectForKey:@"customerId"],nil];
////        [webcon commonGetSharedRequest:GETREPAIRCUSTOMERDETAIL wsparas:arry];
//        
////        dic = @{@"CUSTOMER_ID":[[self.tableViewDataArrS objectAtIndex:indexPath.row]objectForKey:@"CUSTOMER_ID"]};
//    }
//    
}
-(NSMutableDictionary *)readershuDICimform
{
    NSMutableDictionary *dic=[NSMutableDictionary dictionary];
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *path=[paths objectAtIndex:0];
    NSString *str=[path stringByAppendingPathComponent:@"Dic.text"];
    dic=[NSMutableDictionary dictionaryWithContentsOfFile:str];
    //nslog(@"%@",dic);
    return dic;
}
//接受车主详细信息
-(void)ownerDetail:(NSNotification *)notification
{
    NSMutableDictionary *theJson = [NSJSONSerialization JSONObjectWithData:(NSData *)notification.object options:NSJSONReadingMutableLeaves error:nil];
    self.customerDetailsViewController = [[CustomerDetailsViewController alloc]initWithNibName:@"CustomerDetailsViewController" bundle:nil];
    self.customerDetailsViewController.customerDataDicionary = theJson;
    [self.navigationController pushViewController:self.customerDetailsViewController animated:YES];
}
//接受车辆详细信息
-(void)getRepairCarDetail:(NSNotification *)notification
{
    NSMutableDictionary *theJson = [NSJSONSerialization JSONObjectWithData:(NSData *)notification.object options:NSJSONReadingMutableLeaves error:nil];
    self.vehicledataeditViewController= [[VehicleDataEditViewController alloc]init];
    self.vehicledataeditViewController.vehicleDictionary = theJson;
    [self.navigationController pushViewController:self.vehicledataeditViewController animated:YES];
}
#pragma armk - 两个TableViewCell内容
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger row = [indexPath row];
    if(tableView == self.detailTableView)
    {
//        车主
        static NSString *indetfire = @"cell";
        InformationCellS *cell = (InformationCellS *)[tableView dequeueReusableCellWithIdentifier:indetfire];
        if(nil == cell)
        {
            
            cell = [[InformationCellS alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indetfire];
            tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        }
     
        cell.cellLabelOne.text = [[self.tableViewDataArrS objectAtIndex:row]objectForKey:@"CREATE_DATE"];
        cell.cellLabelTwo.text = [[self.tableViewDataArrS objectAtIndex:row]objectForKey:@"CUSTOMER_ID"];
        cell.cellLabelThree.text = [[self.tableViewDataArrS objectAtIndex:row]objectForKey:@"CUSTOMER_NAME"];
        
//        NSNumber *nature = [[self.tableViewDataArrS objectAtIndex:row]objectForKey:@"NATURE_NAME"];
//        cell.cellLabelFour.text = nature.stringValue;
        NSString * nature = [[[self.tableViewDataArrS objectAtIndex:row]objectForKey:@"NATURE_NAME"] stringValue];
        if ([nature isEqualToString:@"11901002"]) {
            cell.cellLabelFour.text = @"个人";
        }
        else if ([nature isEqualToString:@"11901001"]){
        
        cell.cellLabelFour.text = @"公司";
        }
        else{
         cell.cellLabelFour.text = @"";
        }
        
        
        cell.cellLabelFive.text = [[self.tableViewDataArrS objectAtIndex:row]objectForKey:@"CONTACT_MAN"];
        cell.cellLabelSix.text = [[self.tableViewDataArrS objectAtIndex:row]objectForKey:@"MOBILE"];
        cell.cellLabelSeven.text = [[self.tableViewDataArrS objectAtIndex:row]objectForKey:@"TEL"];
        cell.cellLabelEight.text = [[self.tableViewDataArrS objectAtIndex:row]objectForKey:@"ADDRESS"];
                
        return cell;
    }
    if(tableView == self.detailTableView2)
    {
//        车辆
        static NSString *indetfire11 = @"cell";
        InformationCellX *cell = [tableView dequeueReusableCellWithIdentifier:indetfire11];
        if(nil == cell)
        {
            cell = [[InformationCellX alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indetfire11];
            tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        }
        //NSString *manufacture = [self getManufactureNameById:[[self.tableViewDataArrX objectAtIndex:row]objectForKey:@"manufactureName"]];
        //NSString *carColor = [self getCarColorDataNameById:[[self.tableViewDataArrX objectAtIndex:row]objectForKey:@"COLOR"]];

        cell.cellLabelOne.text = [[self.tableViewDataArrX objectAtIndex:row]objectForKey:@"LICENSE"];
        cell.cellLabelTwo.text = [[self.tableViewDataArrX objectAtIndex:row]objectForKey:@"VIN"];
//        cell.cellLabelThree.text = [[self.tableViewDataArrX objectAtIndex:row]objectForKey:@"BRAND"];
        cell.cellLabelThree.text = [self getpinpai:row];
//        cell.cellLabelFour.text = [[self.tableViewDataArrX objectAtIndex:row]objectForKey:@"MODEL"];
        cell.cellLabelFour.text = [self getCheXi:row];
//        cell.cellLabelFive.text = [[self.tableViewDataArrX objectAtIndex:row]objectForKey:@"APACKAGE"];
      cell.cellLabelFive.text = [self getchexing:row];
//        cell.cellLabelSeven.text = [[self.tableViewDataArrX objectAtIndex:row]objectForKey:@"COLOR"];
        cell.cellLabelSeven.text =[self getColor:row];
//        NSNumber *purpose = [[self.tableViewDataArrX objectAtIndex:row]objectForKey:@"VEHICLE_PURPOSE"];
   
       cell.cellLabelEight.text =[self getPurpose:row];
        
        //[[self.tableViewDataArrX objectAtIndex:row]objectForKey:@"emission"];
        //cell.cellLabelEight.text = [[self.tableViewDataArrX objectAtIndex:row]objectForKey:@"VEHICLE_PURPOSE"];
        
        return cell;
    }
    return 0;
}
-(NSString *)getColor:(NSInteger)sender{
    NSString * str = [[self.tableViewDataArrX objectAtIndex:sender]objectForKey:@"COLOR"];
    NSArray *zidianArr=[self readershuDICimform][@"OUTER_COLOR"];
    for(NSDictionary *dic in zidianArr)
    {
        if ([dic[@"COLOR_CODE"] isEqualToString:str]) {
            return dic[@"COLOR_NAME"];
        }
    }
    return nil;


}
-(NSString *)getchexing:(NSInteger)sender{
    NSString * str = [[self.tableViewDataArrX objectAtIndex:sender]objectForKey:@"MODEL"];
    NSArray *zidianArr=[self readershuDICimform][@"MODEL"];
    for(NSDictionary *dic in zidianArr)
    {
        if ([dic[@"MODEL_CODE"] isEqualToString:str]) {
            return dic[@"MODEL_NAME"];
        }
    }
    return nil;
}
-(NSString *)getCheXi:(NSInteger)sender{

    NSString * str = [[self.tableViewDataArrX objectAtIndex:sender]objectForKey:@"SERIES"];
    NSArray *zidianArr=[self readershuDICimform][@"SERIES"];
    for(NSDictionary *dic in zidianArr)
    {
        if ([dic[@"SERIES_CODE"] isEqualToString:str]) {
            return dic[@"SERIES_NAME"];
        }
    }
    return nil;
}
-(NSString *)getPurpose:(NSInteger)sender{
    NSString * str = [[[self.tableViewDataArrX objectAtIndex:sender] objectForKey:@"VEHICLE_PURPOSE"] stringValue];
    NSArray *zidianArr=[self readershuDICimform][@"VEHICLE_PURPOSE"];
    for(NSDictionary *dic in zidianArr)
    {
        if ([dic[@"CODE"] isEqualToString:str]) {
          return dic[@"NAME"];
        }
    }
    return nil;
}

-(NSString *)getpinpai:(NSInteger)sender{
    NSString * str = [[self.tableViewDataArrX objectAtIndex:sender]objectForKey:@"BRAND"];
    NSArray *zidianArr=[self readershuDICimform][@"BRAND"];
    for(NSDictionary *dic in zidianArr)
    {
        if ([dic[@"BRAND_CODE"] isEqualToString:str]) {
            return dic[@"BRAND_NAME"];
        }
    }
    return nil;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 45;
}

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row%2 == 1)
    {
        cell.backgroundColor = [[UIColor alloc]initWithRed:0.96 green:0.96 blue:0.96 alpha:1];
    }
    else
    {
        cell.backgroundColor = [[UIColor alloc]initWithRed:226.00/255 green:226.00/255 blue:226.00/255 alpha:1];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;;
}
//tableView滑动手势删除数据
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(tableView == self.detailTableView)
    {
//        NSLog(@"!!!!!!!!!!%@",[self.tableViewDataArrS objectAtIndex:indexPath.row]);
        if(editingStyle == UITableViewCellEditingStyleDelete)
        {
            [self.tableViewDataArrS removeObjectAtIndex:indexPath.row];
            [self.detailTableView reloadData];
        }
    }
    else if(tableView == self.detailTableView2)
{
    if(editingStyle == UITableViewCellEditingStyleDelete)
    {
        [self.tableViewDataArrX removeObjectAtIndex:indexPath.row];
        [self.detailTableView2 reloadData];
    }
}
}
//修改删除按钮的标题
-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return @"删除";
}


-(void)loadinputPicture
{
    self.vehiclefield1 = [[UITextField alloc]initWithFrame:CGRectMake(145, 120, 150, 30)];//客户名称
    self.vehiclefield1.borderStyle = UITextBorderStyleLine;
    self.vehiclefield1.textColor = [UIColor grayColor];
    self.vehiclefield1.font = [UIFont fontWithName:@"ArialMT" size:14];
    [self.vehiclefield1 setTextAlignment:NSTextAlignmentCenter];
    self.vehiclefield1.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    [self.view addSubview:self.vehiclefield1];
    
    self.vehiclefield2 = [[UITextField alloc]initWithFrame:CGRectMake(145, 165, 150, 30)];//联系电话  车牌号
    self.vehiclefield2.borderStyle = UITextBorderStyleLine;
    self.vehiclefield2.textColor = [UIColor grayColor];
    self.vehiclefield2.font = [UIFont fontWithName:@"ArialMT" size:14];
    [self.vehiclefield2 setTextAlignment:NSTextAlignmentCenter];
    self.vehiclefield2.keyboardType = UIKeyboardTypeNumberPad;
    self.vehiclefield2.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    [self.view addSubview:self.vehiclefield2];
    
    self.vehiclefield3 = [[UITextField alloc]initWithFrame:CGRectMake(395, 120, 253, 30)];//车架号
    self.vehiclefield3.borderStyle = UITextBorderStyleLine;
   
    self.vehiclefield3.textColor = [UIColor grayColor];
    self.vehiclefield3.font = [UIFont fontWithName:@"ArialMT" size:14];
    [self.vehiclefield3 setTextAlignment:NSTextAlignmentCenter];
    self.vehiclefield3.keyboardType = UIKeyboardTypeNumberPad;
    self.vehiclefield3.delegate=self;
    self.vehiclefield3.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    [self.view addSubview:self.vehiclefield3];
    
    self.vehiclefield4 = [[UITextField alloc]initWithFrame:CGRectMake(745, 120, 140, 30)];//联系人
    self.vehiclefield4.borderStyle = UITextBorderStyleLine;
    self.vehiclefield4.textColor = [UIColor grayColor];
    self.vehiclefield4.font = [UIFont fontWithName:@"ArialMT" size:14];
    [self.vehiclefield4 setTextAlignment:NSTextAlignmentCenter];
    self.vehiclefield4.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    [self.view addSubview:self.vehiclefield4];
}



-(void)loadfixedPicture
{
    
    self.homeBackButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.homeBackButton setImage:[UIImage imageNamed:@"房子.png"] forState:UIControlStateNormal];
    [self.homeBackButton setFrame:CGRectMake(60, 42, 68, 40)];
    [self.homeBackButton addTarget:self action:@selector(InformatBack:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.homeBackButton];
    
    UILabel *jiedai = [[UILabel alloc]initWithFrame:CGRectMake(200, 45, 200, 40)];
    jiedai.text = @"车主车辆信息";
    jiedai.backgroundColor = [UIColor clearColor];
    jiedai.textColor = [UIColor grayColor];
    jiedai.font = [UIFont systemFontOfSize:30];
    [self.view addSubview:jiedai];
    
    UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(20, 100, 1000, 11)];
    image.image = [UIImage imageNamed:@"渐变分割线.png"];
    [self.view addSubview:image];
    
    UILabel *customer = [[UILabel alloc]initWithFrame:CGRectMake(65, 120, 90, 30)];
    customer.text = @"客户名称:";
    customer.backgroundColor = [UIColor clearColor];
    customer.textColor = [UIColor grayColor];
    customer.font = [UIFont fontWithName:@"ArialMT" size:16];
    [self.view addSubview:customer];
    
    UILabel *handphone = [[UILabel alloc]initWithFrame:CGRectMake(65, 165, 90, 30)];
    handphone.text = @"联系电话:";
    handphone.backgroundColor = [UIColor clearColor];
    handphone.textColor = [UIColor grayColor];
    handphone.font = [UIFont fontWithName:@"ArialMT" size:16];
    [self.view addSubview:handphone];
    
    UILabel *phone = [[UILabel alloc]initWithFrame:CGRectMake(315, 120, 90, 30)];
    phone.text = @"手       机:";
    phone.backgroundColor = [UIColor clearColor];
    phone.textColor = [UIColor grayColor];
    phone.font = [UIFont fontWithName:@"ArialMT" size:16];
    [self.view addSubview:phone];
    
    UILabel *entry = [[UILabel alloc]initWithFrame:CGRectMake(315, 165, 90, 30)];
    entry.text = @"录入时间:";
    entry.backgroundColor = [UIColor clearColor];
    entry.textColor = [UIColor grayColor];
    entry.font = [UIFont fontWithName:@"ArialMT" size:16];
    [self.view addSubview:entry];
    
    UILabel *contact = [[UILabel alloc]initWithFrame:CGRectMake(665, 120, 90, 30)];
    contact.text = @"联  系  人:";
    contact.backgroundColor = [UIColor clearColor];
    contact.textColor = [UIColor grayColor];
    contact.font = [UIFont fontWithName:@"ArialMT" size:16];
    [self.view addSubview:contact];
    
    UILabel *customerature = [[UILabel alloc]initWithFrame:CGRectMake(665, 165, 90, 30)];
    customerature.text = @"客户性质:";
    customerature.backgroundColor = [UIColor clearColor];
    customerature.textColor = [UIColor grayColor];
    customerature.font = [UIFont fontWithName:@"ArialMT" size:16];
    [self.view addSubview:customerature];
    
    UILabel *zhi = [[UILabel alloc]initWithFrame:CGRectMake(515, 165, 30, 30)];
    zhi.text = @"至";
    zhi.backgroundColor = [UIColor clearColor];
    zhi.textColor = [UIColor grayColor];
    zhi.font = [UIFont fontWithName:@"ArialMT" size:16];
    [self.view addSubview:zhi];
    
    UILabel *honda = [[UILabel alloc]initWithFrame:CGRectMake(100, 420, 80, 40)];
    honda.text = @"传祺品牌";
    honda.backgroundColor = [UIColor clearColor];
    honda.textColor = [UIColor grayColor];
    honda.font = [UIFont fontWithName:@"ArialMT" size:16];
    [self.view addSubview:honda];
    
    UILabel *nohonda = [[UILabel alloc]initWithFrame:CGRectMake(100, 465, 90, 40)];
    nohonda.text = @"非传祺品牌";
    nohonda.backgroundColor = [UIColor clearColor];
    nohonda.textColor = [UIColor grayColor];
    nohonda.font = [UIFont fontWithName:@"ArialMT" size:16];
    [self.view addSubview:nohonda];
    
    UILabel *licensePlate = [[UILabel alloc]initWithFrame:CGRectMake(190, 420, 80, 40)];
    licensePlate.text = @"车牌号:";
    licensePlate.backgroundColor = [UIColor clearColor];
    licensePlate.textColor = [UIColor grayColor];
    licensePlate.font = [UIFont fontWithName:@"ArialMT" size:16];
    [self.view addSubview:licensePlate];
    
    UILabel *customerName = [[UILabel alloc]initWithFrame:CGRectMake(190, 465, 80, 40)];
    customerName.text = @"客户名:";
    customerName.backgroundColor = [UIColor clearColor];
    customerName.textColor = [UIColor grayColor];
    customerName.font = [UIFont fontWithName:@"ArialMT" size:16];
    [self.view addSubview:customerName];
    
    UILabel *frame = [[UILabel alloc]initWithFrame:CGRectMake(405, 420, 80, 40)];
    frame.text = @"车架号:";
    frame.backgroundColor = [UIColor clearColor];
    frame.textColor = [UIColor grayColor];
    frame.font = [UIFont fontWithName:@"ArialMT" size:16];
    [self.view addSubview:frame];
    
    UILabel *model = [[UILabel alloc]initWithFrame:CGRectMake(405, 465, 80, 40)];
    model.text = @"车   型:";
    model.backgroundColor = [UIColor clearColor];
    model.textColor = [UIColor grayColor];
    model.font = [UIFont fontWithName:@"ArialMT" size:16];
    [self.view addSubview:model];
    
    UILabel *species = [[UILabel alloc]initWithFrame:CGRectMake(650, 420, 80, 40)];
    species.text = @"车系名:";
    species.backgroundColor = [UIColor clearColor];
    species.textColor = [UIColor grayColor];
    species.font = [UIFont fontWithName:@"ArialMT" size:16];
    [self.view addSubview:species];
    
    UILabel *belong = [[UILabel alloc]initWithFrame:CGRectMake(650, 465, 80, 40)];
    belong.text = @"所属店:";
    belong.backgroundColor = [UIColor clearColor];
    belong.textColor = [UIColor grayColor];
    belong.font = [UIFont fontWithName:@"ArialMT" size:16];
    //[self.view addSubview:belong];
    
    UIImageView *divider = [[UIImageView alloc]initWithFrame:CGRectMake(16, 403, 1135, 6)];
    divider.image = [UIImage imageNamed:@"分割线.png"];
    [self.view addSubview:divider];
        
#pragma mark - 客户查询按钮
    UIButton *vehiclequery = [[UIButton alloc]initWithFrame:CGRectMake(913, 120, 58, 31)];
    [vehiclequery setTitle:@"查 询" forState:UIControlStateNormal];
    [vehiclequery setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [vehiclequery setBackgroundImage:[UIImage imageNamed:@"ht05-1.png"] forState:UIControlStateNormal];
    [vehiclequery addTarget:self action:@selector(VehicleQuery:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:vehiclequery];
    
    UIButton *newvehicle = [[UIButton alloc]initWithFrame:CGRectMake(912, 165, 60, 32)];
    [newvehicle setTitle:@"新 增" forState:UIControlStateNormal];
    [newvehicle setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [newvehicle setBackgroundImage:[UIImage imageNamed:@"改-灰but.png"] forState:UIControlStateNormal];
    [newvehicle addTarget:self action:@selector(newvehicle:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:newvehicle];
    
    //录入时间下拉按钮
    self.entrylabel1 = [[UILabel alloc]initWithFrame:CGRectMake(395, 165, 110, 30)];
    [self.entrylabel1 setBackgroundColor:[UIColor whiteColor]];
    self.entrylabel1.layer.borderColor = [[UIColor grayColor]CGColor];
    self.entrylabel1.layer.borderWidth = 0.8;
    [self.view addSubview:self.entrylabel1];
    self.entrybutton1 = [[UIButton alloc]initWithFrame:CGRectMake(396, 166, 108, 28)];
    [self.entrybutton1 setBackgroundImage:[UIImage imageNamed:@"下拉框.png"] forState:UIControlStateNormal];
    [self.entrybutton1 addTarget:self action:@selector(entrybutton1:) forControlEvents:UIControlEventTouchUpInside];
    [self.entrybutton1 setTitle:@"< 空 >" forState:UIControlStateNormal];
    self.entrybutton1.titleLabel.font = [UIFont fontWithName:@"ArialMT" size:15];
    [self.entrybutton1 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [self.view addSubview:self.entrybutton1];
    
    NSDate *senddate=[NSDate date];
    NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init];
    [dateformatter setDateFormat:@"YYYY-MM-dd"];
    self.PikString = [dateformatter stringFromDate:senddate];
    self.entrylabel2 = [[UILabel alloc]initWithFrame:CGRectMake(540, 165, 110, 30)];
    [self.entrylabel2 setBackgroundColor:[UIColor whiteColor]];
    self.entrylabel2.layer.borderColor = [[UIColor grayColor]CGColor];
    self.entrylabel2.layer.borderWidth = 0.8;
    [self.view addSubview:self.entrylabel2];
    self.entrybutton2 = [[UIButton alloc]initWithFrame:CGRectMake(541, 166, 108, 28)];
    [self.entrybutton2 setBackgroundImage:[UIImage imageNamed:@"下拉框.png"] forState:UIControlStateNormal];
    [self.entrybutton2 addTarget:self action:@selector(entrybutton2:) forControlEvents:UIControlEventTouchUpInside];
    [self.entrybutton2 setTitle:self.PikString forState:UIControlStateNormal];
    self.entrybutton2.titleLabel.font = [UIFont fontWithName:@"ArialMT" size:15];
    [self.entrybutton2 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [self.view addSubview:self.entrybutton2];

    //客户性质下拉按钮
    self.entrylabel3 = [[UILabel alloc]initWithFrame:CGRectMake(745, 165, 140, 30)];
    [self.entrylabel3 setBackgroundColor:[UIColor whiteColor]];
    self.entrylabel3.layer.borderColor = [[UIColor grayColor]CGColor];
    self.entrylabel3.layer.borderWidth = 0.8;
    [self.view addSubview:self.entrylabel3];
    self.entrybutton3 = [[UIButton alloc]initWithFrame:CGRectMake(746, 166, 138, 28)];
    [self.entrybutton3 setBackgroundImage:[UIImage imageNamed:@"下拉框.png"] forState:UIControlStateNormal];
    [self.entrybutton3 addTarget:self action:@selector(entrybutton3:) forControlEvents:UIControlEventTouchUpInside];
    [self.entrybutton3 setTitle:@"< 空 >" forState:UIControlStateNormal];
    self.entrybutton3.titleLabel.font = [UIFont fontWithName:@"ArialMT" size:15];
    [self.entrybutton3 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [self.view addSubview:self.entrybutton3];
}
-(void)entrybutton1:(id)sender
{
    self.datePicker = [[UIDatePicker alloc]initWithFrame:CGRectMake(0, 0, 280, 160)];
    self.datePicker.locale = [[NSLocale alloc] initWithLocaleIdentifier:NSLocalizedString(@"Chinese", @"")];
    self.datePicker.datePickerMode = UIDatePickerModeDate;
    [self.datePicker addTarget:self action:@selector(dateChanged:) forControlEvents:UIControlEventValueChanged];
    //
    panleCon = [[UIViewController alloc] init];
    [panleCon.view addSubview:self.datePicker];
    self.popCon = [[UIPopoverController alloc] initWithContentViewController:panleCon];
    self.popCon.popoverContentSize = CGSizeMake(280.0f, 200.0f);
    
    [self.popCon presentPopoverFromRect:CGRectMake(20, 0, 10, 40) inView:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
    UIButton *pickerBut = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [pickerBut setBackgroundColor:[UIColor clearColor]];
    [pickerBut setTitle:@"今 天" forState:UIControlStateNormal];
    [pickerBut setFrame:CGRectMake(20, 165, 80, 30)];
    [pickerBut addTarget:self action:@selector(pickerBut:) forControlEvents:UIControlEventTouchUpInside];
    [panleCon.view addSubview:pickerBut];
    UIButton *pickerBut1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [pickerBut1 setBackgroundColor:[UIColor clearColor]];
    [pickerBut1 setTitle:@"清 除" forState:UIControlStateNormal];
    [pickerBut1 setFrame:CGRectMake(180, 165, 80, 30)];
    [pickerBut1 addTarget:self action:@selector(pickerBut1:) forControlEvents:UIControlEventTouchUpInside];
    [panleCon.view addSubview:pickerBut1];
}
-(void)dateChanged:(id)sender{
    UIDatePicker *contro = (UIDatePicker*)sender;
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    self.PikString = [formatter stringFromDate:contro.date];
    [self.entrybutton1 setTitle:self.PikString forState:UIControlStateNormal];
}
-(void)pickerBut:(id)sender
{
    NSDate *senddate=[NSDate date];
    NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init];
    [dateformatter setDateFormat:@"YYYY-MM-dd"];
    self.PikString = [dateformatter stringFromDate:senddate];
    [self.entrybutton1 setTitle:self.PikString forState:UIControlStateNormal];
    [self.popCon dismissPopoverAnimated:YES];
}
-(void)pickerBut1:(id)sender
{
    [self.entrybutton1 setTitle:@"< 空 >" forState:UIControlStateNormal];
    [self.popCon dismissPopoverAnimated:YES];
}
-(void)entrybutton2:(id)sender
{
    self.datePicker = [[UIDatePicker alloc]initWithFrame:CGRectMake(0, 0, 280, 160)];
    self.datePicker.locale = [[NSLocale alloc] initWithLocaleIdentifier:NSLocalizedString(@"Chinese", @"")];
    self.datePicker.datePickerMode = UIDatePickerModeDate;
    [self.datePicker addTarget:self action:@selector(dateChanged2:) forControlEvents:UIControlEventValueChanged];
    //
    panleCon = [[UIViewController alloc] init];
    [panleCon.view addSubview:self.datePicker];
    self.popCon = [[UIPopoverController alloc] initWithContentViewController:panleCon];
    self.popCon.popoverContentSize = CGSizeMake(280.0f, 200.0f);
    
    [self.popCon presentPopoverFromRect:CGRectMake(20, 0, 10, 40) inView:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
    UIButton *pickerBut = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [pickerBut setBackgroundColor:[UIColor clearColor]];
    [pickerBut setTitle:@"今 天" forState:UIControlStateNormal];
    [pickerBut setFrame:CGRectMake(20, 165, 80, 30)];
    [pickerBut addTarget:self action:@selector(pickerBut2:) forControlEvents:UIControlEventTouchUpInside];
    [panleCon.view addSubview:pickerBut];
    UIButton *pickerBut1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [pickerBut1 setBackgroundColor:[UIColor clearColor]];
    [pickerBut1 setTitle:@"清 除" forState:UIControlStateNormal];
    [pickerBut1 setFrame:CGRectMake(180, 165, 80, 30)];
    [pickerBut1 addTarget:self action:@selector(pickerBut3:) forControlEvents:UIControlEventTouchUpInside];
    [panleCon.view addSubview:pickerBut1];
}
-(void)dateChanged2:(id)sender{
    UIDatePicker *contro = (UIDatePicker*)sender;
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    self.PikString = [formatter stringFromDate:contro.date];
    [self.entrybutton2 setTitle:self.PikString forState:UIControlStateNormal];
}
-(void)pickerBut2:(id)sender
{
    NSDate *senddate=[NSDate date];
    NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init];
    [dateformatter setDateFormat:@"YYYY-MM-dd"];
    self.PikString = [dateformatter stringFromDate:senddate];
    [self.entrybutton2 setTitle:self.PikString forState:UIControlStateNormal];
    [self.popCon dismissPopoverAnimated:YES];
}
-(void)pickerBut3:(id)sender
{
    [self.entrybutton2 setTitle:@"< 空 >" forState:UIControlStateNormal];
    [self.popCon dismissPopoverAnimated:YES];
}

#pragma mark - 客户查询按钮的回调
-(void)VehicleQuery:(id)sender
{
    [SVProgressHUD showWithStatus:@"请等待...."];

    [self searchKeHuXinxi];
    
//    [self.customerQueryDic setValue:[NSString stringWithFormat:@"%d",self.tableViewDataArrS.count+1] forKey:@"FROM"];
//    [self.customerQueryDic setValue:[NSString stringWithFormat:@"%d",self.tableViewDataArrS.count+10] forKey:@"TO"];
    [self.customerQueryDic setValue:[NSString stringWithFormat:@"%d",fromZ] forKey:@"FROM"];
    [self.customerQueryDic setValue:[NSString stringWithFormat:@"%d",toZ] forKey:@"TO"];
    NSLog(@"self.customerQueryDic : %@",self.customerQueryDic);

    [MyAFNetWorkManager postWithParam:self.customerQueryDic andAction:@"QUERY_OWNER" finish:^(NSData *data, NSDictionary *obj, NSError *error) {
        [SVProgressHUD dismiss];
        if (error == nil)
        {
            NSLog(@"车主查询 json is %@",obj);
            NSDictionary *dic = obj;
            if([[dic valueForKey:@"SUCCESS"] integerValue]==1)
            {
                NSArray *array = [dic objectForKey:@"TM_OWNER"];
                [self.tableViewDataArrS removeAllObjects];
                    [self.tableViewDataArrS addObjectsFromArray:array];
                    [self.detailTableView reloadData];
               
                
            }
        }
        else{
            [SVProgressHUD showErrorWithStatus:error.localizedDescription];
        }
        
    }];
}

-(void)searchCustomer:(NSNotification *)notification
{
    NSMutableDictionary *theJson = [NSJSONSerialization JSONObjectWithData:(NSData *)notification.object options:NSJSONReadingMutableLeaves error:Nil];
//    self.tableViewDataArrS = NSmut [theJson objectForKey:@"customerList"];
    self.tableViewDataArrS = [NSMutableArray arrayWithArray:[theJson objectForKey:@"customerList"]];
    [self.detailTableView reloadData];
    [SVProgressHUD dismiss];
}
#pragma mark - 车主搜索条件
-(void)searchKeHuXinxi
{
    self.customerQueryDic = [NSMutableDictionary dictionaryWithCapacity:4];
    if(![self.entrybutton1.titleLabel.text isEqualToString:@"< 空 >"])
    {
        [self.customerQueryDic setValue:self.entrybutton1.titleLabel.text forKey:@"INPUT_DATE_FROM"];
        [self.customerQuery addObject:@"inputDate"];
        [self.customerQuery addObject:self.entrybutton1.titleLabel.text];
    }
    
    if(![self.entrybutton2.titleLabel.text isEqualToString:@"< 空 >"])
    {
        [self.customerQueryDic setValue:self.entrybutton2.titleLabel.text forKey:@"INPUT_DATE_TO"];
        [self.customerQuery addObject:@"inputDate"];
        [self.customerQuery addObject:self.entrybutton1.titleLabel.text];
    }
    
    if ([self.entrybutton3.titleLabel.text isEqualToString:@"个人"]) {
        [self.customerQueryDic setObject:@"11901002" forKey:@"CUSTOMER_TYPE"];
    }
    if ([self.entrybutton3.titleLabel.text isEqualToString:@"公司"]) {
        [self.customerQueryDic setObject:@"11901001" forKey:@"CUSTOMER_TYPE"];
    }
    
//    if([self.entrybutton3.titleLabel.text isEqualToString:@"政府机关"])
//    {
//        [self.customerQueryDic setValue:@"CUSTOMER_TYPE" forKey:@"C1"];
//        [self.customerQuery addObject:@"customerType"];
//        [self.customerQuery addObject:@"C1"];
//    }
//    if([self.entrybutton3.titleLabel.text isEqualToString:@"企业单位"])
//    {
//        [self.customerQueryDic setValue:@"CUSTOMER_TYPE" forKey:@"C2"];
//        [self.customerQuery addObject:@"customerType"];
//        [self.customerQuery addObject:@"C2"];
//    }
//    if([self.entrybutton3.titleLabel.text isEqualToString:@"私人"])
//    {
//        [self.customerQueryDic setValue:@"CUSTOMER_TYPE" forKey:@"C3"];
//        [self.customerQuery addObject:@"customerType"];
//        [self.customerQuery addObject:@"C3"];
//    }
    if(self.vehiclefield1.text != nil)
    {
        NSString * str = [self.vehiclefield1.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        [self.customerQueryDic setValue:str forKey:@"CUSTOMER_NAME"];
        [self.customerQuery addObject:@"customerName"];
        [self.customerQuery addObject:self.vehiclefield1.text];
    }
    if(self.vehiclefield2.text != nil)
    {
        NSString * str = [self.vehiclefield2.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        [self.customerQueryDic setValue:str forKey:@"TEL"];
        [self.customerQuery addObject:@"tel"];
        [self.customerQuery addObject:self.vehiclefield2.text];
    }
    if(self.vehiclefield3.text != nil)
    {
        NSString * str = [self.vehiclefield3.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        [self.customerQueryDic setValue:str forKey:@"MOBILE"];
        [self.customerQuery addObject:@"mobile"];
        [self.customerQuery addObject:self.vehiclefield3.text];
    }
    if(self.vehiclefield4.text != nil)
    {
         NSString * str = [self.vehiclefield4.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        [self.customerQueryDic setValue:str forKey:@"CONTACT_MAN"];
        [self.customerQuery addObject:@"contactMan"];
        [self.customerQuery addObject:self.vehiclefield4.text];
    }
}
#pragma mark - 客户新增按钮的回调
-(void)newvehicle:(id)sender
{
//    [SVProgressHUD showWithStatus:@"请等待...."];
    
    KehuXinZengViewController *cvc = [[KehuXinZengViewController alloc]initWithNibName:@"KehuXinZengViewController" bundle:nil];
    [self.navigationController pushViewController:cvc animated:YES];
}
#pragma mark - 车辆新增按钮的回调
-(void)newvehicle2:(id)sender
{
    self.carInformationViewController = [[NewCarInformationViewController alloc]init];

    [self.navigationController pushViewController:self.carInformationViewController animated:YES];
}
#pragma mark - 车辆查询按钮的回调
-(void)VehicleQuery2:(id)sender
{
//    [SVProgressHUD showWithStatus:@"请等待...."];
    [self searchCheLiangXinxi];
//    [self.carQueryDic setValue:[NSString stringWithFormat:@"%d",self.tableViewDataArrX.count+1] forKey:@"FROM"];
//    [self.carQueryDic setValue:[NSString stringWithFormat:@"%d",self.tableViewDataArrX.count+10] forKey:@"TO"];
   

    if(_state == YES)
    {
        [self.carQueryDic setValue:@"1" forKey:@"IS_HONDA"];
        [self.carQuery addObject:@"whetherHonda"];
        [self.carQuery addObject:@"1"];
    }
    if(_state == NO)
    {
        [self.carQueryDic setValue:@"0" forKey:@"IS_HONDA"];
        [self.carQuery addObject:@"whetherHonda"];
        [self.carQuery addObject:@"0"];
    }
    
    [self.carQueryDic setValue:[NSString stringWithFormat:@"%d",fromL] forKey:@"FROM"];
    [self.carQueryDic setValue:[NSString stringWithFormat:@"%d",toL] forKey:@"TO"];
    NSLog(@"车辆查询dic %@",self.carQueryDic);
    [MyAFNetWorkManager postWithParam:self.carQueryDic andAction:@"QUERY_VEHICLE" finish:^(NSData *data, NSDictionary *obj, NSError *error) {
        [SVProgressHUD dismiss];
        if (error == nil)
        {
            NSDictionary *dic = obj;
            NSLog(@"车辆查询 json is %@",obj);
            if([[dic valueForKey:@"SUCCESS"]integerValue]==1)
            {
                NSArray *array = [dic objectForKey:@"TM_VEHICLE"];
                [self.tableViewDataArrX removeAllObjects];
                    [self.tableViewDataArrX addObjectsFromArray:array];
                    [self.detailTableView2 reloadData];
            }
        }
        else{
            [SVProgressHUD showErrorWithStatus:error.localizedDescription];
        }
        
    }];
    
}
//-(void)searchRepairCar:(NSNotification *)notification
//{
//    NSMutableDictionary *theJson = [NSJSONSerialization JSONObjectWithData:(NSData *)notification.object options:NSJSONReadingMutableLeaves error:Nil];
//
//    self.tableViewDataArrX = [NSMutableArray arrayWithArray:[theJson objectForKey:@"customerList"]];
//    [self.detailTableView2 reloadData];
//    [SVProgressHUD dismiss];
//}
#pragma mark - 车辆搜索条件
-(void)searchCheLiangXinxi
{
    self.carQueryDic = [NSMutableDictionary dictionaryWithCapacity:5];
    if(![self.secondfield1.text isEqualToString:@""])
    {
        NSString * str = [self.secondfield1.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        [self.carQueryDic setValue:str forKey:@"PLATE_NUMBER"];
        [self.carQuery addObject:@"plateNumber"];
        [self.carQuery addObject:self.secondfield1.text];
    }
    if(![self.secondfield2.text isEqualToString:@""])
    {
        NSString * str = [self.secondfield2.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        [self.carQueryDic setValue:str forKey:@"CUSTOMER_NAME"];
        [self.carQuery addObject:@"customerName"];
        [self.carQuery addObject:self.secondfield2.text];
    }
    if(![self.secondfield3.text isEqualToString:@""])
    {
        NSString * str = [self.secondfield3.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        [self.carQueryDic setValue:str forKey:@"VIN"];
        [self.carQuery addObject:@"vin"];
        [self.carQuery addObject:self.secondfield3.text];
    }
    if(![self.secondbutton1.titleLabel.text isEqualToString:@"< 空 >"])
    {
        [self.carQueryDic setValue:self.carTypeId forKey:@"CAR_TYPE_ID"];
        [self.carQuery addObject:@"carTypeId"];
        [self.carQuery addObject:self.carTypeId];
//        NSLog(@"——————————车型：%@",self.carTypeId);
    }
    if (![self.secondbutton2.titleLabel.text isEqualToString:@"< 空 >"])
    {
        [self.carQueryDic setValue:self.carClassId forKey:@"CAR_CLASS_NAME"];
        [self.carQuery addObject:@"carClassName"];
        [self.carQuery addObject:self.carClassId];
    }
}


-(void)loadSecondPartPicture
{
#pragma mark - 车辆信息查询按钮
    UIButton *vehiclequery2 = [[UIButton alloc]initWithFrame:CGRectMake(913, 425, 58, 31)];
    [vehiclequery2 setTitle:@"查 询" forState:UIControlStateNormal];
    [vehiclequery2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [vehiclequery2 setBackgroundImage:[UIImage imageNamed:@"ht05-1.png"] forState:UIControlStateNormal];
    [vehiclequery2 addTarget:self action:@selector(VehicleQuery2:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:vehiclequery2];
    
    UIButton *newvehicle2 = [[UIButton alloc]initWithFrame:CGRectMake(912, 470, 60, 32)];
    [newvehicle2 setTitle:@"新 增" forState:UIControlStateNormal];
    [newvehicle2 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [newvehicle2 setBackgroundImage:[UIImage imageNamed:@"改-灰but.png"] forState:UIControlStateNormal];
    [newvehicle2 addTarget:self action:@selector(newvehicle2:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:newvehicle2];
    
    self.choosebutton1 = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.choosebutton1 setFrame:CGRectMake(60, 415, 45, 45)];
    [self.choosebutton1 setImage:[UIImage imageNamed:@"选择中.png"] forState:UIControlStateNormal];
    [self.choosebutton1 addTarget:self action:@selector(choosebutton1:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.choosebutton1];
    
    self.choosebutton2 = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.choosebutton2 setFrame:CGRectMake(60, 460, 45, 45)];
    [self.choosebutton2 setImage:[UIImage imageNamed:@"选择空.png"] forState:UIControlStateNormal];
    [self.choosebutton2 addTarget:self action:@selector(choosebutton2:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.choosebutton2];
    ////////车牌号
    self.secondfield1 = [[UITextField alloc]initWithFrame:CGRectMake(250, 425, 140, 30)];
    self.secondfield1.borderStyle = UITextBorderStyleLine;
    self.secondfield1.textColor = [UIColor grayColor];
    self.secondfield1.font = [UIFont fontWithName:@"ArialMT" size:15];
    [self.secondfield1 setTextAlignment:NSTextAlignmentCenter];
    self.secondfield1.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    self.secondfield1.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
    self.secondfield1.delegate = self;
    [self.view addSubview:self.secondfield1];
    
    ///////////客户名
    self.secondfield2 = [[UITextField alloc]initWithFrame:CGRectMake(250, 470, 140, 30)];
    self.secondfield2.borderStyle = UITextBorderStyleLine;
    self.secondfield2.textColor = [UIColor grayColor];
    self.secondfield2.font = [UIFont fontWithName:@"ArialMT" size:15];
    [self.secondfield2 setTextAlignment:NSTextAlignmentCenter];
    self.secondfield2.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        self.secondfield2.delegate = self;
    [self.view addSubview:self.secondfield2];

    //车架号
    self.secondfield3 = [[UITextField alloc]initWithFrame:CGRectMake(470, 425, 165, 30)];
    self.secondfield3.borderStyle = UITextBorderStyleLine;
    self.secondfield3.textColor = [UIColor grayColor];
    [self.secondfield3 setTextAlignment:NSTextAlignmentCenter];
    self.secondfield3.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    //设置键盘
    self.secondfield3.autocapitalizationType=UITextAutocapitalizationTypeAllCharacters;
    self.secondfield3.font = [UIFont fontWithName:@"ArialMT" size:14];
    self.secondfield3.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
    self.secondfield3.delegate = self;
    [self.view addSubview:self.secondfield3];
    
    
    //车型
    self.secondlabel1 = [[UILabel alloc]initWithFrame:CGRectMake(470, 470, 165, 30)];
    [self.secondlabel1 setBackgroundColor:[UIColor whiteColor]];
    self.secondlabel1.layer.borderColor = [[UIColor grayColor]CGColor];
    self.secondlabel1.layer.borderWidth = 0.8;
    [self.view addSubview:self.secondlabel1];
    self.secondbutton1 = [[UIButton alloc]initWithFrame:CGRectMake(471, 471, 163, 28)];
    [self.secondbutton1 setBackgroundImage:[UIImage imageNamed:@"下拉框.png"] forState:UIControlStateNormal];
    [self.secondbutton1 addTarget:self action:@selector(secondbutton1:) forControlEvents:UIControlEventTouchUpInside];
    [self.secondbutton1 setTitle:@"< 空 >" forState:UIControlStateNormal];
    self.secondbutton1.titleLabel.font = [UIFont fontWithName:@"ArialMT" size:15];
    [self.secondbutton1 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [self.view addSubview:self.secondbutton1];
    
//    车系
    self.secondlabel2 = [[UILabel alloc]initWithFrame:CGRectMake(715, 425, 150, 30)];
    [self.secondlabel2 setBackgroundColor:[UIColor whiteColor]];
    self.secondlabel2.layer.borderColor = [[UIColor grayColor]CGColor];
    self.secondlabel2.layer.borderWidth = 0.8;
    [self.view addSubview:self.secondlabel2];
    self.secondbutton2 = [[UIButton alloc]initWithFrame:CGRectMake(716, 426, 148, 28)];
    [self.secondbutton2 setBackgroundImage:[UIImage imageNamed:@"下拉框.png"] forState:UIControlStateNormal];
    [self.secondbutton2 addTarget:self action:@selector(secondbutton2:) forControlEvents:UIControlEventTouchUpInside];
    [self.secondbutton2 setTitle:@"< 空 >" forState:UIControlStateNormal];
    self.secondbutton2.titleLabel.font = [UIFont fontWithName:@"ArialMT" size:15];
    [self.secondbutton2 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [self.view addSubview:self.secondbutton2];

    
//    self.secondlabel3 = [[UILabel alloc]initWithFrame:CGRectMake(715, 470, 150, 30)];
//    [self.secondlabel3 setBackgroundColor:[UIColor whiteColor]];
//    self.secondlabel3.layer.borderColor = [[UIColor grayColor]CGColor];
//    self.secondlabel3.layer.borderWidth = 0.8;
//    [self.view addSubview:self.secondlabel3];
//    self.secondbutton3 = [[UIButton alloc]initWithFrame:CGRectMake(716, 471, 148, 28)];
//    [self.secondbutton3 setBackgroundImage:[UIImage imageNamed:@"下拉框.png"] forState:UIControlStateNormal];
//    [self.secondbutton3 addTarget:self action:@selector(secondbutton3:) forControlEvents:UIControlEventTouchUpInside];
//    [self.secondbutton3 setTitle:@"< 空 >" forState:UIControlStateNormal];
//    self.secondbutton3.titleLabel.font = [UIFont fontWithName:@"ArialMT" size:15];
//    [self.secondbutton3 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
//    [self.view addSubview:self.secondbutton3];
}

#pragma mark - 返回上一页面按钮的回调方法
-(void)InformatBack:(id)sender
{
    [self removeNotification];
    
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)entrybutton3:(id)sender  //客户性质
{
    if (!contentCon) {
        contentCon=[[popContentViewController alloc] initWithNibName:@"popContentViewController" bundle:nil];
    }
    contentCon.delegate = self;
    contentCon.btnSender=sender;
    self.popCon = [[UIPopoverController alloc] initWithContentViewController:contentCon];
    [DDPopoverBackgroundView setTintColor:[UIColor colorWithRed:234 green:248 blue:242 alpha:0.9]];
    [DDPopoverBackgroundView setArrowBase:30.0];//箭头
    [DDPopoverBackgroundView setArrowHeight:15.0];
    [DDPopoverBackgroundView setContentInset:1.0];
    [self.popCon setPopoverBackgroundViewClass:[DDPopoverBackgroundView class]];
    [self.popCon setPopoverContentSize:CGSizeMake(self.entrybutton3.frame.size.width, 80)];
    [self.popCon presentPopoverFromRect:CGRectMake(10, 10, 120, 20) inView:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
    
    NSMutableArray *carTypeArray=[[NSMutableArray alloc] init];
//    [carTypeArray addObject:@"< 空 >"];
//    [carTypeArray addObject:@"政府机关"];
//    [carTypeArray addObject:@"企业单位"];
//    [carTypeArray addObject:@"私人"];
    
    [carTypeArray addObject:@"个人"];
    [carTypeArray addObject:@"公司"];
    contentCon.list = carTypeArray;
    
    
    
    [contentCon.myTableView reloadData];
}

#pragma mark - 弹出回调方法
-(void)selectDelegate:(NSInteger)row btn:(UIButton *)btn
{
    if(row >= 0)
    {
        if(btn == self.secondbutton1)
        {
//            self.carTypeId = [[self.carTypeArray objectAtIndex:row-1] objectForKey:@"carTypeId"];
            self.carTypeId = [self.carTypeArray objectAtIndex:row];
        }
        if (btn==self.secondbutton2)
        {
            self.carClassId = [self.carClassArray objectAtIndex:row];
//            self.carClassId = [[self.carClassArray objectAtIndex:row-1] objectForKey:@"carClassCode"];
        }
    }
    else
    {
        if(btn == self.secondbutton1)
        {
            self.carTypeId = @"< 空 >";
        }
        if(btn == self.secondbutton2)
        {
            self.carClassId = @"< 空 >";
        }
    }
    
    [self.popCon dismissPopoverAnimated:YES];
    self.popCon = nil;
}

-(void)secondbutton1:(id)sender   //车型
{
    if ([self.secondbutton2.titleLabel.text isEqualToString:@"< 空 >"]) {
        UIAlertView *alerVeiw = [[UIAlertView alloc] initWithTitle:@"请选择车辆" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alerVeiw show];
        return;
    }
//    webService *web=[[webService alloc] init];
//    web.methodName = GETCARTYPENAMELIST;
//    [web commonGetSharedRequest:GETCARTYPENAMELIST wsparas:nil];
    
    if (!contentCon) {
        contentCon=[[popContentViewController alloc] initWithNibName:@"popContentViewController" bundle:nil];
    }
    contentCon.delegate = self;
    contentCon.btnSender=sender;
    self.popCon = [[UIPopoverController alloc] initWithContentViewController:contentCon];
    [DDPopoverBackgroundView setTintColor:[UIColor colorWithRed:234 green:248 blue:242 alpha:0.9]];
    [DDPopoverBackgroundView setArrowBase:30.0];//箭头
    [DDPopoverBackgroundView setArrowHeight:15.0];
    [DDPopoverBackgroundView setContentInset:1.0];
    [self.popCon setPopoverBackgroundViewClass:[DDPopoverBackgroundView class]];
    [self.popCon setPopoverContentSize:CGSizeMake(self.secondbutton1.frame.size.width, 200)];
    [self.popCon presentPopoverFromRect:CGRectMake(10, 10, 120, 20) inView:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
    
    NSArray *zidianArr=[self readershuDICimform][@"MODEL"];
    NSMutableArray *modelArr = [[NSMutableArray alloc]init];
    [self.carTypeArray removeAllObjects];
    
    for(NSDictionary *dic in zidianArr)
    {
        if ([dic[@"SERIES_CODE"] isEqualToString:self.carClassId]) {
            [modelArr addObject:dic[@"MODEL_NAME"]];
            [self.carTypeArray addObject:dic[@"MODEL_CODE"]];
        }
       
    }
    contentCon.list = modelArr;
    [contentCon.myTableView reloadData];
    
}
-(void)getCarType:(NSNotification*)notification{
    
    NSDictionary *theJson = [NSJSONSerialization JSONObjectWithData:(NSData*)notification.object options:NSJSONReadingMutableLeaves error:Nil];
    self.carTypeArray = [theJson objectForKey:@"results"];
    NSMutableArray *carTypeArray=[[NSMutableArray alloc] init];
    [carTypeArray addObject:@"< 空 >"];
    
    for (int i=0; i<[[theJson objectForKey:@"results"] count]; i++) {
        
        [carTypeArray addObject: [[[theJson objectForKey:@"results"] objectAtIndex:i] objectForKey:@"carTypeName"]];
    }
    contentCon.list = carTypeArray;
    
    [contentCon.myTableView reloadData];
}

-(void)secondbutton2:(id)sender     //车系名
{
//    webService *web=[[webService alloc] init];
//    web.methodName = GETCARCLASSNAMELIST;
//    [web commonGetSharedRequest:GETCARCLASSNAMELIST wsparas:nil];

    if (!contentCon) {
        contentCon=[[popContentViewController alloc] initWithNibName:@"popContentViewController" bundle:nil];
    }
    contentCon.delegate = self;
    contentCon.btnSender=sender;
    self.popCon = [[UIPopoverController alloc] initWithContentViewController:contentCon];
    [DDPopoverBackgroundView setTintColor:[UIColor colorWithRed:234 green:248 blue:242 alpha:0.9]];
    [DDPopoverBackgroundView setArrowBase:30.0];//箭头
    [DDPopoverBackgroundView setArrowHeight:15.0];
    [DDPopoverBackgroundView setContentInset:1.0];
    [self.popCon setPopoverBackgroundViewClass:[DDPopoverBackgroundView class]];
    [self.popCon setPopoverContentSize:CGSizeMake(self.secondbutton2.frame.size.width, 200)];
    [self.popCon presentPopoverFromRect:CGRectMake(10, 10, 130, 20) inView:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
    
    NSArray *zidianArr=[self readershuDICimform][@"SERIES"];
   
    NSMutableArray *seriesArr = [[NSMutableArray alloc]init];
    [self.carClassArray removeAllObjects];
    
    for(NSDictionary *dic in zidianArr)
    {
        [seriesArr addObject:dic[@"SERIES_NAME"]];
        [self.carClassArray addObject:dic[@"SERIES_CODE"]];
    }
   
    contentCon.list = seriesArr;
    [contentCon.myTableView reloadData];
}
-(void)getCarClass:(NSNotification*)notification{
    
    NSDictionary *theJson = [NSJSONSerialization JSONObjectWithData:(NSData*)notification.object options:NSJSONReadingMutableLeaves error:Nil];
    self.carClassArray = [theJson objectForKey:@"results"];
    NSMutableArray *carClassArray=[[NSMutableArray alloc] init];
    [carClassArray addObject:@"< 空 >"];
    
    for (int i=0; i<[[theJson objectForKey:@"results"] count]; i++) {
        
        [carClassArray addObject: [[[theJson objectForKey:@"results"] objectAtIndex:i] objectForKey:@"carClassName"]];
    }
    contentCon.list = carClassArray;
    [contentCon.myTableView reloadData];
}

-(void)secondbutton3:(id)sender     //所属店
{
    webService *web=[[webService alloc] init];
    web.methodName = GETSHOPNAMELIST;
    [web commonGetSharedRequest:GETSHOPNAMELIST wsparas:nil];

    if (!contentCon) {
        contentCon=[[popContentViewController alloc] initWithNibName:@"popContentViewController" bundle:nil];
    }
    contentCon.delegate = self;
    contentCon.btnSender=sender;
    self.popCon = [[UIPopoverController alloc] initWithContentViewController:contentCon];
    [DDPopoverBackgroundView setTintColor:[UIColor colorWithRed:234 green:248 blue:242 alpha:0.9]];
    [DDPopoverBackgroundView setArrowBase:30.0];//箭头
    [DDPopoverBackgroundView setArrowHeight:15.0];
    [DDPopoverBackgroundView setContentInset:1.0];
    [self.popCon setPopoverBackgroundViewClass:[DDPopoverBackgroundView class]];
    [self.popCon setPopoverContentSize:CGSizeMake(self.secondbutton3.frame.size.width, 200)];
    [self.popCon presentPopoverFromRect:CGRectMake(10, 10, 130, 20) inView:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
-(void)shopIdList:(NSNotification*)notification{
    
    NSDictionary *theJson = [NSJSONSerialization JSONObjectWithData:(NSData*)notification.object options:NSJSONReadingMutableLeaves error:Nil];
    self.shopArray = [theJson objectForKey:@"results"];
    NSMutableArray *carClassArray=[[NSMutableArray alloc] init];
    [carClassArray addObject:@"< 空 >"];
    
    for (int i=0; i<[[theJson objectForKey:@"results"] count]; i++) {
        
        [carClassArray addObject: [[[theJson objectForKey:@"results"] objectAtIndex:i] objectForKey:@"shopId"]];
    }
    
    contentCon.list = carClassArray;
    [contentCon.myTableView reloadData];
}

- (void) niDropDownDelegateMethod: (NIDropDown *) sender
{
    dropDown = nil;
}


-(void)choosebutton1:(id)sender
{
    _state = YES;
        [self.choosebutton1 setImage:[UIImage imageNamed:@"选择中.png"] forState:UIControlStateNormal];
        [self.choosebutton2 setImage:[UIImage imageNamed:@"选择空.png"] forState:UIControlStateNormal];
}
-(void)choosebutton2:(id)sender
{
    _state = NO;
        [self.choosebutton2 setImage:[UIImage imageNamed:@"选择中.png"] forState:UIControlStateNormal];
        [self.choosebutton1 setImage:[UIImage imageNamed:@"选择空.png"] forState:UIControlStateNormal];
}
-(void)loadtitlelabelPicture
{
    NSMutableArray *labelMutabelArray = [[NSMutableArray alloc]initWithObjects:@"录入日期",@"客户编号",@"客户名称",@"客户性质",@"联系人",@"手机号",@"联系电话",@"  联系地址", nil];
    for(int i = 0; i < 8;i++)
    {
        UILabel *titlelabel = [[UILabel alloc]initWithFrame:CGRectMake((60+i*114), 215, 120, 40)];
        titlelabel.BackgroundColor = [[UIColor alloc]initWithRed:0.96 green:0.96 blue:0.96 alpha:1];
        titlelabel.text = [labelMutabelArray objectAtIndex:i];
        titlelabel.textColor = [UIColor grayColor];
        titlelabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:16];
        [titlelabel setTextAlignment:NSTextAlignmentCenter];
        [self.view addSubview:titlelabel];
    }
}
-(void)loadNewTitleLabelPicture
{
    UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(60, 520, 110, 45)];
    label1.backgroundColor = [[UIColor alloc]initWithRed:0.96 green:0.96 blue:0.96 alpha:1];
    label1.textColor = [UIColor grayColor];
    label1.font = [UIFont fontWithName:@"Arial-BoldMT" size:16];
    label1.text =@"车牌号";
    label1.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:label1];
    UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(label1.frame), 520, 160, 45)];
    label2.backgroundColor = [[UIColor alloc]initWithRed:0.96 green:0.96 blue:0.96 alpha:1];
    label2.textColor = [UIColor grayColor];
    label2.font = [UIFont fontWithName:@"Arial-BoldMT" size:16];
    label2.text =@"车架号";
    label2.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:label2];
    UILabel *label3 = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(label2.frame), 520, 120, 45)];
    label3.backgroundColor = [[UIColor alloc]initWithRed:0.96 green:0.96 blue:0.96 alpha:1];
    label3.textColor = [UIColor grayColor];
    label3.font = [UIFont fontWithName:@"Arial-BoldMT" size:16];
    label3.text =@"  品牌";
    label3.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:label3];

    UILabel *label4 = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(label3.frame), 520, 150, 45)];
    label4.backgroundColor = [[UIColor alloc]initWithRed:0.96 green:0.96 blue:0.96 alpha:1];
    label4.textColor = [UIColor grayColor];
    label4.font = [UIFont fontWithName:@"Arial-BoldMT" size:16];
    label4.text =@"车系";
    label4.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:label4];
    
    UILabel *label5 = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(label4.frame), 520, 190, 45)];
    label5.backgroundColor = [[UIColor alloc]initWithRed:0.96 green:0.96 blue:0.96 alpha:1];
    label5.textColor = [UIColor grayColor];
    label5.font = [UIFont fontWithName:@"Arial-BoldMT" size:16];
    label5.text =@"车型";
    label5.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:label5];
    
    UILabel *label6 = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(label5.frame), 520, 90, 45)];
    label6.backgroundColor = [[UIColor alloc]initWithRed:0.96 green:0.96 blue:0.96 alpha:1];
    label6.textColor = [UIColor grayColor];
    label6.font = [UIFont fontWithName:@"Arial-BoldMT" size:16];
    label6.text =@"  颜色";
    label6.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:label6];
    
    UILabel *label7 = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(label6.frame), 520, 100, 45)];
    label7.backgroundColor = [[UIColor alloc]initWithRed:0.96 green:0.96 blue:0.96 alpha:1];
    label7.textColor = [UIColor grayColor];
    label7.font = [UIFont fontWithName:@"Arial-BoldMT" size:16];
    label7.text =@"车辆用途";
    label7.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:label7];
    
//    UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(60, 520, 260, 45)];
//    label1.text = @"      车牌号                   车架号        ";
//    label1.backgroundColor = [[UIColor alloc]initWithRed:0.96 green:0.96 blue:0.96 alpha:1];
//    label1.textColor = [UIColor grayColor];
//    label1.font = [UIFont fontWithName:@"Arial-BoldMT" size:16];
//    [self.view addSubview:label1];
//
//   
//        UILabel *titlelabel = [[UILabel alloc]initWithFrame:CGRectMake(308, 520, 720, 45)];
//        titlelabel.backgroundColor = [[UIColor alloc]initWithRed:0.96 green:0.96 blue:0.96 alpha:1];
//   
//        titlelabel.text = @"                品牌                     车系                           车型                               颜色              车辆用途";
//        titlelabel.textColor = [UIColor grayColor];
//        titlelabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:16];
//    
//        [self.view addSubview:titlelabel];
   
}

- (void)keyboardHide:(NSNotification *)notif   //键盘即将消失的时候点done归为view
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.3];
    [self.view setFrame:CGRectMake(0, 0, 1024, 768)];
    [UIView commitAnimations];
}
//生产厂家
-(void)getManufactureList:(NSNotification*)notification
{
    NSMutableDictionary *theJson = [NSJSONSerialization JSONObjectWithData:(NSData*)notification.object options:NSJSONReadingMutableLeaves error:Nil];
    _manufacturerDataNameId = [NSMutableArray arrayWithArray:[theJson objectForKey:@"manufactureList"]];
}
-(NSString *)getManufactureNameById:(NSString *)manufactureId
{
    for(int i = 0; i < [_manufacturerDataNameId count];i++)
    {
        if([[[_manufacturerDataNameId objectAtIndex:i]objectForKey:@"manufactureId"] isEqualToString:manufactureId])
        {
            return [[_manufacturerDataNameId objectAtIndex:i] objectForKey:@"manufactureName"];
        }
    }
    return nil;
}
//车辆颜色
-(void)getcarColorList:(NSNotification*)notification
{
    NSDictionary *theJson = [NSJSONSerialization JSONObjectWithData:(NSData*)notification.object options:NSJSONReadingMutableLeaves error:Nil];
    _CarColorDataNameId = [theJson objectForKey:@"results"];
}
-(NSString *)getCarColorDataNameById:(NSString *)carColorId
{
    for(int i = 0; i < [_CarColorDataNameId count];i++)
    {
        if([[[_CarColorDataNameId objectAtIndex:i]objectForKey:@"carColorId"] isEqualToString:carColorId])
        {
            return [[_CarColorDataNameId objectAtIndex:i] objectForKey:@"carColorName"];
        }
    }
    return nil;
}
-(void)informationHomeBackButton
{
    [self.homeBackButton setImage:[UIImage imageNamed:@"返回.png"] forState:UIControlStateNormal];
    [self.homeBackButton setFrame:CGRectMake(75, 32, 45, 60)];
}
-(void)addNotification
{
    //注册消息（车主）
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(searchCustomer:) name:SEARCHREPAIRCUSTOMER object:nil];//基本信息
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(ownerDetail:) name:GETREPAIRCUSTOMERDETAIL object:nil];//详细信息
    //注册消息（车辆)
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(searchRepairCar:) name:SEARCHREPAIRCAR object:nil]; //基本信息
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(getRepairCarDetail:) name:GETREPAIRCARDETAIL object:nil]; //详细信息
    
    //获取车型列表
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getCarType:) name:GETCARTYPENAMELIST object:nil];
    //获取车种名列表
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getCarClass:) name:GETCARCLASSNAMELIST object:nil];
    //直属店
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(shopIdList:) name:GETSHOPNAMELIST object:nil];
    //生产厂家列表
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getManufactureList:) name:GETMANUFACTURELIST object:nil];
    //车辆颜色列表
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getcarColorList:) name:GETCARCOLORLIST object:nil];
}
-(void)removeNotification
{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}
//-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
//{
//    if(self.vehiclefield3==textField){
//    NSCharacterSet *cs;
//    cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERS]invertedSet];
//    
//    self.vehiclefield3.text = [[string componentsSeparatedByCharactersInSet:cs]componentsJoinedByString:@""]; //按cs分离出数组,数组按@""分离出字符串
//    
//    BOOL canChange = [string isEqualToString:self.vehiclefield3.text];
//    
//    return canChange;
//    }
//}
@end
